import { axiosInstance } from '../axios'
import CommonConfig from '../../assets/js/config'
import qs from 'qs'

const qsConfig = {
  arrayFormat: 'repeat',
  skipNulls: true,
  format: 'RFC3986'
}
const machinestatusUrl = CommonConfig.machinestatusUrl
const reportUrl = CommonConfig.reportUrl

// 列举设备生产计数统计(程序)
function getDeviceProductCount (params) {
  const newUrl = `${reportUrl}/v1/workshops/device_product_count`
  let reqData = {
    params,
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  return axiosInstance.post(newUrl, reqData.params).then((res) => {
    return Promise.resolve(res)
  })
}
// 列举设备生产计数统计(图表)
function getDeviceProductCountTime (params) {
  const newUrl = `${reportUrl}/v1/workshops/device_product_count_time`
  let reqData = {
    params,
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  return axiosInstance.post(newUrl, reqData.params).then((res) => {
    return Promise.resolve(res)
  })
}
// 生产计数统计设备结果集
function getDeviceProductCountResult (params) {
  const newUrl = `${machinestatusUrl}/v1/workshops/device_product_count/device_result`
  let reqData = {
    params,
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  return axiosInstance.post(newUrl, reqData.params).then((res) => {
    return Promise.resolve(res)
  })
}
// 导出生产计数报表
function exportProductCountReports (params) {
  const newUrl = `${reportUrl}/v1/workshops/excel:export`
  return axiosInstance.post(newUrl, params).then((res) => {
    return Promise.resolve(res)
  })
}

function exportProductCountReportsByDispatch (params) {
  const newUrl = `${reportUrl}/v1/workshops/dispatching/excel:export`
  return axiosInstance.post(newUrl, params).then((res) => {
    return Promise.resolve(res)
  })
}

function getDeviceProductCountList (params) {
  const newUrl = `${reportUrl}/v1/workshops/device_product_count:list`
  return axiosInstance.post(newUrl, params).then((res) => {
    return Promise.resolve(res)
  })
}
export default {
  exportProductCountReports,
  getDeviceProductCount,
  getDeviceProductCountTime,
  getDeviceProductCountResult,
  getDeviceProductCountList,
  exportProductCountReportsByDispatch
}
